package com.shy.config.util;

import com.shy.config.model.SecurityUser;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Set;

/**
 * 认证授权工具类
 */
public class AuthUtils {
    /**
     * 获取当前登录用户信息
     * @return
     */
    public static SecurityUser getLoginSecurityUser(){
        return (SecurityUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    /**
     * 获取登录用户的id
     * @return
     */
    public static Integer getLoginSecurityUserId(){
        return getLoginSecurityUser().getId();
    }

    /**
     * 获取用户角色集合
     * @return
     */
    public static Set<String> getLoginSecurityUserRoles(){
        return getLoginSecurityUser().getRoles() ;
    }
}
